﻿@{
    ViewBag.Title = "Update";
    Layout = "~/Views/Shared/_Admin_Layout.cshtml";
    ViewBag.Controller = "contents";
    ViewBag.Cate = "Nội dung";
    ViewBag.Module = "Cập nhật nội dung";
}

<script type="text/javascript">
    $(function () {
        $('#_btn_add').live('click', function () {

            // Get the editor instance that you want to interact with.
            var editor = CKEDITOR.instances.editor;
            $("textarea#editor").text(editor.getData()).text();

            var name    = $("#_name").val();
            var content = $("#editor").text();

            //Check Name
            if (name == "") {
                show_errors("Chưa nhập tiêu đề.");
                return false;
            }

            //Check Contents
            if (content.length <= 10) {
                show_errors("Nội dung sản phẩm phải lớn hơn 10 ký tự.");
                return false;
            }

            UpdateItem("@ViewBag.Controller");

            return false;
        });
    });
</script>

<!--Tabs-->
<div class="tabs">
    <span class="item"><a href="/admin" title="">Bảng điều khiển</a></span>
    <span class="icon-arrow">&gt;</span>
    <span class="item"><a href="/admin/@ViewBag.Controller" title="">@ViewBag.Cate</a></span>
    <span class="icon-arrow">&gt;</span>
    <span class="item">Cập nhật</span>
</div>
<!--End Tabs-->

<!--Container-->
<div class="container">
	<form class="table-content" id="_PostData" method="post">
        <div class="list-btn">
            <a href="/admin/@ViewBag.Controller" class="btn btn-primary" title="Danh sách">Danh sách</a>
            @if (ViewBag.View == null)
            { 
                <input type="submit" class="btn btn-success" id="_btn_add" value="Lưu" />
            }
            else
            {
                <input type="submit" class="btn btn-warning" id="_btn_add" value="Cập nhật" />
            }
        </div>
        <div class="clearAll"></div>
        <div class="notice"><span class="close-notice icon-remove"></span></div>
		<div class="title"><span class="icon-user"></span>@ViewBag.Module</div>
		<div class="error"></div>
		<div class="box-field">
            <input type="hidden" name="id" id="_id" value="@if (ViewBag.View != null){ @ViewBag.View.id }"/>
            <table class="altrowstable" id="alternatecolor">
                <tr>
                    <th>Tên Field</th><th>Input Field</th>
                </tr>
                <tr>
                    <td>Tiêu đề</td>
                    <td><input type="text" name="name" id="_name" value="@if (ViewBag.View != null){ @ViewBag.View.name }" placeholder="Ex: Giới thiệu" maxlength="50" /></td>
                </tr>
                <tr>
                    <td>Nội dung</td>
                    <td><textarea name="contents" class="span9" id="editor" style="height:100px">@if (ViewBag.View != null){ @ViewBag.View.contents }</textarea></td>
                </tr>
            </table>
		</div>
	</form>         
</div>
<!--End Container-->

<script>
    // Replace the <textarea id="editor1"> with an CKEditor instance.
    CKEDITOR.replace('editor');
</script>